home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / ResultSet.java < prev    next >
Text File  |  1998-09-22  |  25KB  |  577 lines

  1. /*
  2.  * @(#)ResultSet.java    1.8 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.sql;
  16.  
  17. import java.math.BigDecimal;
  18.  
  19. /**
  20.  * <P>A ResultSet provides access to a table of data generated by
  21.  * executing a Statement. The table rows are retrieved in
  22.  * sequence. Within a row its column values can be accessed in any
  23.  * order.
  24.  * 
  25.  * <P>A ResultSet maintains a cursor pointing to its current row of
  26.  * data.  Initially the cursor is positioned before the first row.
  27.  * The 'next' method moves the cursor to the next row.
  28.  *
  29.  * <P>The getXXX methods retrieve column values for the current
  30.  * row.  You can retrieve values either using the index number of the
  31.  * column, or by using the name of the column.  In general using the 
  32.  * column index will be more efficient.  Columns are numbered from 1.
  33.  *
  34.  * <P>For maximum portability, ResultSet columns within each row should be
  35.  * read in left-to-right order and each column should be read only once.
  36.  *
  37.  * <P>For the getXXX methods, the JDBC driver attempts to convert the
  38.  * underlying data to the specified Java type and returns a suitable
  39.  * Java value.  See the JDBC specification for allowable mappings
  40.  * from SQL types to Java types with the ResultSet.getXXX methods.
  41.  *
  42.  * <P>Column names used as input to getXXX methods are case
  43.  * insensitive.  When performing a getXXX using a column name, if
  44.  * several columns have the same name, then the value of the first
  45.  * matching column will be returned. The column name option is
  46.  * designed to be used when column names are used in the SQL
  47.  * query. For columns that are NOT explicitly named in the query, it
  48.  * is best to use column numbers. If column names were used there is
  49.  * no way for the programmer to guarantee that they actually refer to
  50.  * the intended columns.
  51.  *
  52.  * <P>A ResultSet is automatically closed by the Statement that
  53.  * generated it when that Statement is closed, re-executed, or is used
  54.  * to retrieve the next result from a sequence of multiple results.
  55.  * 
  56.  * <P>The number, types and properties of a ResultSet's columns are
  57.  * provided by the ResulSetMetaData object returned by the getMetaData
  58.  * method.
  59.  *
  60.  * @see Statement#executeQuery 
  61.  * @see Statement#getResultSet 
  62.  * @see ResultSetMetaData 
  63.  */
  64.  
  65. public interface ResultSet {
  66.  
  67.     /**
  68.      * A ResultSet is initially positioned before its first row; the
  69.      * first call to next makes the first row the current row; the
  70.      * second call makes the second row the current row, etc. 
  71.      *
  72.      * <P>If an input stream from the previous row is open, it is
  73.      * implicitly closed. The ResultSet's warning chain is cleared
  74.      * when a new row is read.
  75.      *
  76.      * @return true if the new current row is valid; false if there
  77.      * are no more rows 
  78.      * @exception SQLException if a database-access error occurs.
  79.      */
  80.     boolean next() throws SQLException;
  81.  
  82.  
  83.     /**
  84.      * In some cases, it is desirable to immediately release a
  85.      * ResultSet's database and JDBC resources instead of waiting for
  86.      * this to happen when it is automatically closed; the close
  87.      * method provides this immediate release.
  88.      *
  89.      * <P><B>Note:</B> A ResultSet is automatically closed by the
  90.      * Statement that generated it when that Statement is closed,
  91.      * re-executed, or is used to retrieve the next result from a
  92.      * sequence of multiple results. A ResultSet is also automatically
  93.      * closed when it is garbage collected.  
  94.      *
  95.      * @exception SQLException if a database-access error occurs.
  96.      */
  97.     void close() throws SQLException;
  98.  
  99.     /**
  100.      * A column may have the value of SQL NULL; wasNull reports whether
  101.      * the last column read had this special value.
  102.      * Note that you must first call getXXX on a column to try to read
  103.      * its value and then call wasNull() to find if the value was
  104.      * the SQL NULL.
  105.      *
  106.      * @return true if last column read was SQL NULL
  107.      * @exception SQLException if a database-access error occurs.
  108.      */
  109.     boolean wasNull() throws SQLException;
  110.     
  111.     //======================================================================
  112.     // Methods for accessing results by column index
  113.     //======================================================================
  114.  
  115.     /**
  116.      * Get the value of a column in the current row as a Java String.
  117.      *
  118.      * @param columnIndex the first column is 1, the second is 2, ...
  119.      * @return the column value; if the value is SQL NULL, the result is null
  120.      * @exception SQLException if a database-access error occurs.
  121.      */
  122.     String getString(int columnIndex) throws SQLException;
  123.  
  124.     /**
  125.      * Get the value of a column in the current row as a Java boolean.
  126.      *
  127.      * @param columnIndex the first column is 1, the second is 2, ...
  128.      * @return the column value; if the value is SQL NULL, the result is false
  129.      * @exception SQLException if a database-access error occurs.
  130.      */
  131.     boolean getBoolean(int columnIndex) throws SQLException;
  132.  
  133.     /**
  134.      * Get the value of a column in the current row as a Java byte.
  135.      *
  136.      * @param columnIndex the first column is 1, the second is 2, ...
  137.      * @return the column value; if the value is SQL NULL, the result is 0
  138.      * @exception SQLException if a database-access error occurs.
  139.      */
  140.     byte getByte(int columnIndex) throws SQLException;
  141.  
  142.     /**
  143.      * Get the value of a column in the current row as a Java short.
  144.      *
  145.      * @param columnIndex the first column is 1, the second is 2, ...
  146.      * @return the column value; if the value is SQL NULL, the result is 0
  147.      * @exception SQLException if a database-access error occurs.
  148.      */
  149.     short getShort(int columnIndex) throws SQLException;
  150.  
  151.     /**
  152.      * Get the value of a column in the current row as a Java int.
  153.      *
  154.      * @param columnIndex the first column is 1, the second is 2, ...
  155.      * @return the column value; if the value is SQL NULL, the result is 0
  156.      * @exception SQLException if a database-access error occurs.
  157.      */
  158.     int getInt(int columnIndex) throws SQLException;
  159.  
  160.     /**
  161.      * Get the value of a column in the current row as a Java long.
  162.      *
  163.      * @param columnIndex the first column is 1, the second is 2, ...
  164.      * @return the column value; if the value is SQL NULL, the result is 0
  165.      * @exception SQLException if a database-access error occurs.
  166.      */
  167.     long getLong(int columnIndex) throws SQLException;
  168.  
  169.     /**
  170.      * Get the value of a column in the current row as a Java float.
  171.      *
  172.      * @param columnIndex the first column is 1, the second is 2, ...
  173.      * @return the column value; if the value is SQL NULL, the result is 0
  174.      * @exception SQLException if a database-access error occurs.
  175.      */
  176.     float getFloat(int columnIndex) throws SQLException;
  177.  
  178.     /**
  179.      * Get the value of a column in the current row as a Java double.
  180.      *
  181.      * @param columnIndex the first column is 1, the second is 2, ...
  182.      * @return the column value; if the value is SQL NULL, the result is 0
  183.      * @exception SQLException if a database-access error occurs.
  184.      */
  185.     double getDouble(int columnIndex) throws SQLException;
  186.  
  187.     /**
  188.      * Get the value of a column in the current row as a java.lang.BigDecimal object.
  189.      *
  190.      * @param columnIndex the first column is 1, the second is 2, ...
  191.      * @param scale the number of digits to the right of the decimal
  192.      * @return the column value; if the value is SQL NULL, the result is null
  193.      * @exception SQLException if a database-access error occurs.
  194.      */
  195.     BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException;
  196.  
  197.     /**
  198.      * Get the value of a column in the current row as a Java byte array.
  199.      * The bytes represent the raw values returned by the driver.
  200.      *
  201.      * @param columnIndex the first column is 1, the second is 2, ...
  202.      * @return the column value; if the value is SQL NULL, the result is null
  203.      * @exception SQLException if a database-access error occurs.
  204.      */
  205.     byte[] getBytes(int columnIndex) throws SQLException;
  206.  
  207.     /**
  208.      * Get the value of a column in the current row as a java.sql.Date object.
  209.      *
  210.      * @param columnIndex the first column is 1, the second is 2, ...
  211.      * @return the column value; if the value is SQL NULL, the result is null
  212.      * @exception SQLException if a database-access error occurs.
  213.      */
  214.     java.sql.Date getDate(int columnIndex) throws SQLException;
  215.  
  216.     /**
  217.      * Get the value of a column in the current row as a java.sql.Time object.
  218.      *
  219.      * @param columnIndex the first column is 1, the second is 2, ...
  220.      * @return the column value; if the value is SQL NULL, the result is null
  221.      * @exception SQLException if a database-access error occurs.
  222.      */
  223.     java.sql.Time getTime(int columnIndex) throws SQLException;
  224.  
  225.     /**
  226.      * Get the value of a column in the current row as a java.sql.Timestamp object.
  227.      *
  228.      * @param columnIndex the first column is 1, the second is 2, ...
  229.      * @return the column value; if the value is SQL NULL, the result is null
  230.      * @exception SQLException if a database-access error occurs.
  231.      */
  232.     java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException;
  233.  
  234.     /**
  235.      * A column value can be retrieved as a stream of ASCII characters 
  236.      * and then read in chunks from the stream.  This method is particularly
  237.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  238.      * do any necessary conversion from the database format into ASCII.
  239.      *
  240.      * <P><B>Note:</B> All the data in the returned stream must be
  241.      * read prior to getting the value of any other column. The next
  242.      * call to a get method implicitly closes the stream. . Also, a
  243.      * stream may return 0 for available() whether there is data
  244.      * available or not.
  245.      *
  246.      * @param columnIndex the first column is 1, the second is 2, ...
  247.      * @return a Java input stream that delivers the database column value
  248.      * as a stream of one byte ASCII characters.  If the value is SQL NULL
  249.      * then the result is null.  
  250.      * @exception SQLException if a database-access error occurs.
  251.      */
  252.     java.io.InputStream getAsciiStream(int columnIndex) throws SQLException;
  253.  
  254.     /**
  255.      * A column value can be retrieved as a stream of Unicode characters 
  256.      * and then read in chunks from the stream.  This method is particularly
  257.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  258.      * do any necessary conversion from the database format into Unicode.
  259.      *
  260.      * <P><B>Note:</B> All the data in the returned stream must be
  261.      * read prior to getting the value of any other column. The next
  262.      * call to a get method implicitly closes the stream. . Also, a
  263.      * stream may return 0 for available() whether there is data
  264.      * available or not.
  265.      *
  266.      * @param columnIndex the first column is 1, the second is 2, ...
  267.      * @return a Java input stream that delivers the database column value
  268.      * as a stream of two byte Unicode characters.  If the value is SQL NULL
  269.      * then the result is null.  
  270.      * @exception SQLException if a database-access error occurs.
  271.      */
  272.     java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException;
  273.  
  274.     /**
  275.      * A column value can be retrieved as a stream of uninterpreted bytes 
  276.      * and then read in chunks from the stream.  This method is particularly
  277.      * suitable for retrieving large LONGVARBINARY values.
  278.      *
  279.      * <P><B>Note:</B> All the data in the returned stream must be
  280.      * read prior to getting the value of any other column. The next
  281.      * call to a get method implicitly closes the stream. Also, a
  282.      * stream may return 0 for available() whether there is data
  283.      * available or not.
  284.      *
  285.      * @param columnIndex the first column is 1, the second is 2, ...
  286.      * @return a Java input stream that delivers the database column value
  287.      * as a stream of uninterpreted bytes.  If the value is SQL NULL
  288.      * then the result is null.  
  289.      * @exception SQLException if a database-access error occurs.
  290.      */
  291.     java.io.InputStream getBinaryStream(int columnIndex)
  292.         throws SQLException;
  293.  
  294.  
  295.     //======================================================================
  296.     // Methods for accessing results by column name
  297.     //======================================================================
  298.  
  299.     /**
  300.      * Get the value of a column in the current row as a Java String.
  301.      *
  302.      * @param columnName is the SQL name of the column
  303.      * @return the column value; if the value is SQL NULL, the result is null
  304.      * @exception SQLException if a database-access error occurs.
  305.      */
  306.     String getString(String columnName) throws SQLException;
  307.  
  308.     /**
  309.      * Get the value of a column in the current row as a Java boolean.
  310.      *
  311.      * @param columnName is the SQL name of the column
  312.      * @return the column value; if the value is SQL NULL, the result is false
  313.      * @exception SQLException if a database-access error occurs.
  314.      */
  315.     boolean getBoolean(String columnName) throws SQLException;
  316.  
  317.     /**
  318.      * Get the value of a column in the current row as a Java byte.
  319.      *
  320.      * @param columnName is the SQL name of the column
  321.      * @return the column value; if the value is SQL NULL, the result is 0
  322.      * @exception SQLException if a database-access error occurs.
  323.      */
  324.     byte getByte(String columnName) throws SQLException;
  325.  
  326.     /**
  327.      * Get the value of a column in the current row as a Java short.
  328.      *
  329.      * @param columnName is the SQL name of the column
  330.      * @return the column value; if the value is SQL NULL, the result is 0
  331.      * @exception SQLException if a database-access error occurs.
  332.      */
  333.     short getShort(String columnName) throws SQLException;
  334.  
  335.     /**
  336.      * Get the value of a column in the current row as a Java int.
  337.      *
  338.      * @param columnName is the SQL name of the column
  339.      * @return the column value; if the value is SQL NULL, the result is 0
  340.      * @exception SQLException if a database-access error occurs.
  341.      */
  342.     int getInt(String columnName) throws SQLException;
  343.  
  344.     /**
  345.      * Get the value of a column in the current row as a Java long.
  346.      *
  347.      * @param columnName is the SQL name of the column
  348.      * @return the column value; if the value is SQL NULL, the result is 0
  349.      * @exception SQLException if a database-access error occurs.
  350.      */
  351.     long getLong(String columnName) throws SQLException;
  352.  
  353.     /**
  354.      * Get the value of a column in the current row as a Java float.
  355.      *
  356.      * @param columnName is the SQL name of the column
  357.      * @return the column value; if the value is SQL NULL, the result is 0
  358.      * @exception SQLException if a database-access error occurs.
  359.      */
  360.     float getFloat(String columnName) throws SQLException;
  361.  
  362.     /**
  363.      * Get the value of a column in the current row as a Java double.
  364.      *
  365.      * @param columnName is the SQL name of the column
  366.      * @return the column value; if the value is SQL NULL, the result is 0
  367.      * @exception SQLException if a database-access error occurs.
  368.      */
  369.     double getDouble(String columnName) throws SQLException;
  370.  
  371.     /**
  372.      * Get the value of a column in the current row as a java.lang.BigDecimal object.
  373.      *
  374.      * @param columnName is the SQL name of the column
  375.      * @param scale the number of digits to the right of the decimal
  376.      * @return the column value; if the value is SQL NULL, the result is null
  377.      * @exception SQLException if a database-access error occurs.
  378.      */
  379.     BigDecimal getBigDecimal(String columnName, int scale) throws SQLException;
  380.  
  381.     /**
  382.      * Get the value of a column in the current row as a Java byte array.
  383.      * The bytes represent the raw values returned by the driver.
  384.      *
  385.      * @param columnName is the SQL name of the column
  386.      * @return the column value; if the value is SQL NULL, the result is null
  387.      * @exception SQLException if a database-access error occurs.
  388.      */
  389.     byte[] getBytes(String columnName) throws SQLException;
  390.  
  391.     /**
  392.      * Get the value of a column in the current row as a java.sql.Date object.
  393.      *
  394.      * @param columnName is the SQL name of the column
  395.      * @return the column value; if the value is SQL NULL, the result is null
  396.      * @exception SQLException if a database-access error occurs.
  397.      */
  398.     java.sql.Date getDate(String columnName) throws SQLException;
  399.  
  400.     /**
  401.      * Get the value of a column in the current row as a java.sql.Time object.
  402.      *
  403.      * @param columnName is the SQL name of the column
  404.      * @return the column value; if the value is SQL NULL, the result is null
  405.      * @exception SQLException if a database-access error occurs.
  406.      */
  407.     java.sql.Time getTime(String columnName) throws SQLException;
  408.  
  409.     /**
  410.      * Get the value of a column in the current row as a java.sql.Timestamp object.
  411.      *
  412.      * @param columnName is the SQL name of the column
  413.      * @return the column value; if the value is SQL NULL, the result is null
  414.      * @exception SQLException if a database-access error occurs.
  415.      */
  416.     java.sql.Timestamp getTimestamp(String columnName) throws SQLException;
  417.  
  418.     /**
  419.      * A column value can be retrieved as a stream of ASCII characters 
  420.      * and then read in chunks from the stream.  This method is particularly
  421.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  422.      * do any necessary conversion from the database format into ASCII.
  423.      *
  424.      * <P><B>Note:</B> All the data in the returned stream must
  425.      * be read prior to getting the value of any other column. The
  426.      * next call to a get method implicitly closes the stream.
  427.      *
  428.      * @param columnName is the SQL name of the column
  429.      * @return a Java input stream that delivers the database column value
  430.      * as a stream of one byte ASCII characters.  If the value is SQL NULL
  431.      * then the result is null.
  432.      * @exception SQLException if a database-access error occurs.
  433.      */
  434.     java.io.InputStream getAsciiStream(String columnName) throws SQLException;
  435.  
  436.     /**
  437.      * A column value can be retrieved as a stream of Unicode characters 
  438.      * and then read in chunks from the stream.  This method is particularly
  439.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  440.      * do any necessary conversion from the database format into Unicode.
  441.      *
  442.      * <P><B>Note:</B> All the data in the returned stream must
  443.      * be read prior to getting the value of any other column. The
  444.      * next call to a get method implicitly closes the stream.
  445.      *
  446.      * @param columnName is the SQL name of the column
  447.      * @return a Java input stream that delivers the database column value
  448.      * as a stream of two byte Unicode characters.  If the value is SQL NULL
  449.      * then the result is null.
  450.      * @exception SQLException if a database-access error occurs.
  451.      */
  452.     java.io.InputStream getUnicodeStream(String columnName) throws SQLException;
  453.  
  454.     /**
  455.      * A column value can be retrieved as a stream of uninterpreted bytes 
  456.      * and then read in chunks from the stream.  This method is particularly
  457.      * suitable for retrieving large LONGVARBINARY values.
  458.      *
  459.      * <P><B>Note:</B> All the data in the returned stream must
  460.      * be read prior to getting the value of any other column. The
  461.      * next call to a get method implicitly closes the stream.
  462.      *
  463.      * @param columnName is the SQL name of the column
  464.      * @return a Java input stream that delivers the database column value
  465.      * as a stream of uninterpreted bytes.  If the value is SQL NULL
  466.      * then the result is null.
  467.      * @exception SQLException if a database-access error occurs.
  468.      */
  469.     java.io.InputStream getBinaryStream(String columnName)
  470.         throws SQLException;
  471.  
  472.  
  473.     //=====================================================================
  474.     // Advanced features:
  475.     //=====================================================================
  476.  
  477.     /**
  478.      * <p>The first warning reported by calls on this ResultSet is
  479.      * returned. Subsequent ResultSet warnings will be chained to this
  480.      * SQLWarning.
  481.      *
  482.      * <P>The warning chain is automatically cleared each time a new
  483.      * row is read.
  484.      *
  485.      * <P><B>Note:</B> This warning chain only covers warnings caused
  486.      * by ResultSet methods.  Any warning caused by statement methods
  487.      * (such as reading OUT parameters) will be chained on the
  488.      * Statement object. 
  489.      *
  490.      * @return the first SQLWarning or null 
  491.      * @exception SQLException if a database-access error occurs.
  492.      */
  493.     SQLWarning getWarnings() throws SQLException;
  494.  
  495.     /**
  496.      * After this call getWarnings returns null until a new warning is
  497.      * reported for this ResultSet.  
  498.      *
  499.      * @exception SQLException if a database-access error occurs.
  500.      */
  501.     void clearWarnings() throws SQLException;
  502.  
  503.     /**
  504.      * Get the name of the SQL cursor used by this ResultSet.
  505.      *
  506.      * <P>In SQL, a result table is retrieved through a cursor that is
  507.      * named. The current row of a result can be updated or deleted
  508.      * using a positioned update/delete statement that references the
  509.      * cursor name. 
  510.      * 
  511.      * <P>JDBC supports this SQL feature by providing the name of the
  512.      * SQL cursor used by a ResultSet. The current row of a ResultSet
  513.      * is also the current row of this SQL cursor.
  514.      *
  515.      * <P><B>Note:</B> If positioned update is not supported a
  516.      * SQLException is thrown
  517.      *
  518.      * @return the ResultSet's SQL cursor name
  519.      * @exception SQLException if a database-access error occurs.
  520.      */
  521.     String getCursorName() throws SQLException;
  522.  
  523.     /**
  524.      * The number, types and properties of a ResultSet's columns
  525.      * are provided by the getMetaData method.
  526.      *
  527.      * @return the description of a ResultSet's columns
  528.      * @exception SQLException if a database-access error occurs.
  529.      */
  530.     ResultSetMetaData getMetaData() throws SQLException;
  531.  
  532.     /**
  533.      * <p>Get the value of a column in the current row as a Java object.
  534.      *
  535.      * <p>This method will return the value of the given column as a
  536.      * Java object.  The type of the Java object will be the default
  537.      * Java Object type corresponding to the column's SQL type,
  538.      * following the mapping specified in the JDBC spec.
  539.      *
  540.      * <p>This method may also be used to read datatabase specific abstract
  541.      * data types.
  542.      *
  543.      * @param columnIndex the first column is 1, the second is 2, ...
  544.      * @return A java.lang.Object holding the column value.  
  545.      * @exception SQLException if a database-access error occurs.
  546.      */
  547.     Object getObject(int columnIndex) throws SQLException;
  548.  
  549.     /**
  550.      * <p>Get the value of a column in the current row as a Java object.
  551.      *
  552.      * <p>This method will return the value of the given column as a
  553.      * Java object.  The type of the Java object will be the default
  554.      * Java Object type corresponding to the column's SQL type,
  555.      * following the mapping specified in the JDBC spec.
  556.      *
  557.      * <p>This method may also be used to read datatabase specific abstract
  558.      * data types.
  559.      *
  560.      * @param columnName is the SQL name of the column
  561.      * @return A java.lang.Object holding the column value.  
  562.      * @exception SQLException if a database-access error occurs.
  563.      */
  564.     Object getObject(String columnName) throws SQLException;
  565.  
  566.     //----------------------------------------------------------------
  567.  
  568.     /**
  569.      * Map a Resultset column name to a ResultSet column index.
  570.      *
  571.      * @param columnName the name of the column
  572.      * @return the column index
  573.      * @exception SQLException if a database-access error occurs.
  574.      */
  575.     int findColumn(String columnName) throws SQLException;
  576. }
  577.